#import <UIKit/UIKit.h>
/*具体使用
 CascadePickerView *pickerView = [[CascadePickerView alloc] initWithLeftData:leftData columns:2];

 // 设置右侧数据请求回调
 pickerView.requestRightDataBlock = ^(NSString *leftValue, void(^completion)(NSArray *rightData)) {
     // 这里进行实际的网络请求
     [self fetchRightDataForLeftValue:leftValue completion:^(NSArray *data, NSError *error) {
         if (error) {
             // 处理错误
             completion(@[]);
         } else {
             completion(data);
         }
     }];
 };
 
 */
@protocol CascadePickerViewDelegate <NSObject>
@optional
// 选择完成的回调
- (void)cascadePickerView:(id)pickerView didSelectLeftValue:(NSString *)leftValue rightValue:(NSString *)rightValue;
// 取消选择的回调
- (void)cascadePickerViewDidCancel:(id)pickerView;
// 请求右侧数据的代理方法
- (void)cascadePickerView:(id)pickerView requestRightDataForLeftValue:(NSString *)leftValue completion:(void(^)(NSArray *rightData))completion;
@end

@interface CascadePickerView : UIView <UIPickerViewDelegate, UIPickerViewDataSource>

@property (nonatomic, weak) id<CascadePickerViewDelegate> delegate;
@property (nonatomic, copy) void(^completionBlock)(NSString *leftValue, NSString *rightValue);
@property (nonatomic, copy) void(^cancelBlock)(void);
@property (nonatomic, copy) void(^completionIndexBlock)(NSInteger leftIndex, NSInteger rightIndex);

// 左侧数据
@property (nonatomic, strong) NSArray *leftData;
// 右侧数据缓存（左侧值 -> 右侧数据数组）
@property (nonatomic, strong) NSMutableDictionary *rightDataCache;
// 当前选中的左侧索引
@property (nonatomic, assign) NSInteger selectedLeftIndex;
// 当前选中的右侧索引
@property (nonatomic, assign) NSInteger selectedRightIndex;
// 列数
@property (nonatomic, assign) NSInteger columns;

// 请求右侧数据的回调
@property (nonatomic, copy) void(^requestRightDataBlock)(NSString *leftValue, void(^completion)(NSArray *rightData));

// 显示 picker
- (void)show;
// 隐藏 picker
- (void)dismiss;

// 初始化方法
- (instancetype)initWithLeftData:(NSArray *)leftData;
- (instancetype)initWithLeftData:(NSArray *)leftData columns:(NSInteger)columns;

// 外部调用加载右侧数据
- (void)loadRightDataForLeftValue:(NSString *)leftValue withData:(NSArray *)rightData;

@end
